package com.dhecp.project.business.service.impl;

import java.util.Date;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.alibaba.fastjson.JSON;
import com.dhecp.common.core.domain.AjaxResult;
import com.dhecp.common.utils.RandomValueUtils;
import com.dhecp.common.utils.StringUtils;
import com.dhecp.core.constant.DataFiltering;
import com.dhecp.core.utils.PageUtils;
import com.dhecp.framework.util.ShiroUtils;
import com.dhecp.project.business.domain.ProductActive;
import com.dhecp.project.business.domain.ProductActiveCompete;
import com.dhecp.project.business.domain.ProductActiveComponent;
import com.dhecp.project.business.mapper.ProductActiveMapper;
import com.dhecp.project.business.service.ProductActiveService;
import com.dhecp.project.system.service.SysDictionaryForFieldService;

/**
 * 商品库  业务实现层
 * @author DH-Xxj
 * @version 2022年8月12日
 */
@Service
public class ProductActiveServiceImpl implements ProductActiveService {

	@Autowired
	private ProductActiveMapper productActiveMapper;

	@Autowired
	private SysDictionaryForFieldService dictionaryForFieldService;

	/**
     * 查询商品库
	 * @param params
	 * @return List - ProductActive
	 * @throws Exception
	 * @author DH-Xxj
	 */
	@Override
	public List<ProductActive> queryProductActive(Map<String, Object> params) throws Exception{
        params.put(DataFiltering.TABLE_ALIAS, "t1");	//查询表别名
        params.put(DataFiltering.DATA_WHERE, dictionaryForFieldService.getWhereStr(params));	//常规查询条件SQL语句
        params.put(DataFiltering.DATA_SCODE, dictionaryForFieldService.getDataScode(params));	//数据权限查询条件SQL语句

//		String otherWhereStr = "";
//		if ((params.get("otherWhere") == null || params.get("otherWhere") == "") && ShiroUtils.getMandatorLevel() < 6){
//			otherWhereStr = "o1.CUser = '" + ShiroUtils.getMandatorId() + "'";
//		}
//
//		if (!"".equals(otherWhereStr)){
//			params.put("otherWhereStr", otherWhereStr);
//		}

		if (params.get("field") == null || params.get("field") == ""){
			String orderBy = "name asc";
			PageUtils.startPageOrder(orderBy);
		}else{
			PageUtils.startPage();
		}
		
		return productActiveMapper.findProductActive(params);
	}


	/**
     * 查询在库存的商品
	 * @param params
	 * @return List - ProductActive
	 * @throws Exception
	 * @author DH-Xxj
	 */
	@Override
	public List<ProductActive> queryStockProductActive(Map<String, Object> params) throws Exception{
        params.put(DataFiltering.TABLE_ALIAS, "t1");	//查询表别名
        params.put(DataFiltering.DATA_WHERE, dictionaryForFieldService.getWhereStr(params));	//常规查询条件SQL语句
        params.put(DataFiltering.DATA_SCODE, dictionaryForFieldService.getDataScode(params));	//数据权限查询条件SQL语句

//		String otherWhereStr = "";
//		if ((params.get("otherWhere") == null || params.get("otherWhere") == "") && ShiroUtils.getMandatorLevel() < 6){
//			otherWhereStr = "o1.CUser = '" + ShiroUtils.getMandatorId() + "'";
//		}
//
//		if (!"".equals(otherWhereStr)){
//			params.put("otherWhereStr", otherWhereStr);
//		}
		if (params.get("field") == null || params.get("field") == ""){
			String orderBy = "name asc";
			PageUtils.startPageOrder(orderBy);
		}else{
			PageUtils.startPage();
		}

		if (params.get("isAssembly") == null || params.get("isAssembly") == ""){
			return productActiveMapper.findStockProductActive(params);
		}else{
			return productActiveMapper.findManualAssemblyData(params);
		}
	}

	/**
     * 查询商品子件
	 * @param params
	 * @return List - ProductActiveComponent
	 * @throws Exception
	 * @author DH-Xxj
	 */
	@Override
	public List<ProductActiveComponent> queryProductActiveComponent(Map<String, Object> params) throws Exception{
        params.put(DataFiltering.TABLE_ALIAS, "t1");	//查询表别名
        params.put(DataFiltering.DATA_WHERE, dictionaryForFieldService.getWhereStr(params));	//常规查询条件SQL语句
//        params.put(DataFiltering.DATA_SCODE, dictionaryForFieldService.getDataScode(params));	//数据权限查询条件SQL语句

		if (params.get("field") == null || params.get("field") == ""){
			String orderBy = "pcode,name asc";
			PageUtils.startPageOrder(orderBy);
		}else{
			PageUtils.startPage();
		}
		
		return productActiveMapper.findProductActiveComponent(params);
	}

	/**
     * 查询商品竞品库
	 * @param params
	 * @return List - ProductActiveCompete
	 * @throws Exception
	 * @author DH-Xxj
	 */
	@Override
	public List<ProductActiveCompete> queryProductActiveCompete(Map<String, Object> params) throws Exception{
        params.put(DataFiltering.TABLE_ALIAS, "t1");	//查询表别名
        params.put(DataFiltering.DATA_WHERE, dictionaryForFieldService.getWhereStr(params));	//常规查询条件SQL语句
//        params.put(DataFiltering.DATA_SCODE, dictionaryForFieldService.getDataScode(params));	//数据权限查询条件SQL语句

		if (params.get("field") == null || params.get("field") == ""){
			String orderBy = "pcode,asin asc";
			PageUtils.startPageOrder(orderBy);
		}else{
			PageUtils.startPage();
		}
		
		return productActiveMapper.findProductActiveCompete(params);
	}

	/**
	 * 通过guid查询单条商品库
	 * @param guid
	 * @return 实体 ProductActive
	 * @author DH-Xxj
	 */
	@Override
	public ProductActive queryProductActiveByGuid(String guid) {
		return productActiveMapper.findProductActiveByGuid(guid);
	}

	/**
	 * 通过guid查询单条商品库
	 * @param guid
	 * @return 实体 ProductActive
	 * @author DH-Xxj
	 */
	@Override
	public ProductActive queryProductActiveByCode(String code) {
		return productActiveMapper.findProductActiveByCode(code);
	}

	/**
	 * 通过guid查询单条商品子件
	 * @param guid
	 * @return 实体 ProductActiveComponent
	 * @author DH-Xxj
	 */
	@Override
	public ProductActiveComponent queryProductActiveComponentByGuid(String guid) {
		return productActiveMapper.findProductActiveComponentByGuid(guid);
	}

	/**
	 * 通过guid查询单条商品竞品库
	 * @param guid
	 * @return 实体 ProductActiveCompete
	 * @author DH-Xxj
	 */
	@Override
	public ProductActiveCompete queryProductActiveCompeteByGuid(String guid) {
		return productActiveMapper.findProductActiveCompeteByGuid(guid);
	}

	/**
	 * 通过pcode查询商品子件
     * @param pcode 必要参数：商品母件编码
     * @return List - ProductActiveComponent
	 * @author DH-Xxj
	 */
	@Override
	public List<ProductActiveComponent> queryProductActiveComponentBypcode(String pcode) {
		return productActiveMapper.findProductActiveComponentBypcode(pcode);
	}

	/**
	 * 通过Code查询商品子件
     * @param pcode 必要参数：商品母件编码
     * @return List - ProductActiveComponent
	 * @author DH-Xxj
	 */
	@Override
	public ProductActiveComponent querySingleProductActiveComponentByCode(String code) {
		return productActiveMapper.querySingleProductActiveComponentByCode(code);
	}

	/**
	 * 通过Code查询商品子件
     * @param pcode 必要参数：商品母件编码
     * @return List - ProductActiveComponent
	 * @author DH-Xxj
	 */
	@Override
	public List<ProductActiveComponent> queryProductActiveComponentByCode(String code) {
		return productActiveMapper.queryProductActiveComponentByCode(code);
	}

	/**
	 * 通过pcode查询商品竞品库
     * @param pcode 必要参数：商品母件编码
     * @return List - ProductActiveCompete
	 * @author DH-Xxj
	 */
	@Override
	public List<ProductActiveCompete> queryProductActiveCompeteBypcode(String pcode) {
		return productActiveMapper.findProductActiveCompeteBypcode(pcode);
	}
	
	/**
	 * 通过pcode查询基础商品子件 (多条)
     * @param pcode 必要参数：商品母件编码
     * @return List - ProductActiveComponent
	 * @throws Exception
	 * @author DH-Xxj
	 */
	@Override
	public List<ProductActiveComponent> queryProductActiveComponentBypcode2(Map<String, Object> params) throws Exception {
		if (params.get("field") == null || params.get("field") == ""){
			String orderBy = "pcode asc";
			PageUtils.startPageOrder(orderBy);
		}else{
			PageUtils.startPage();
		}
		return productActiveMapper.findInProductActiveComponentBypcode(params);
	}

	/**
	 * 查询已选择的数据
	 * @param params
	 * @return
	 * @throws Exception
	 * @author DH-Xxj
	 */
	@Override
	public List<ProductActive> queryProductActiveList(Map<String, Object> params) throws Exception {
		params.put(DataFiltering.TABLE_ALIAS, "t1");	//查询表别名
		params.put(DataFiltering.DATA_WHERE, dictionaryForFieldService.getWhereStr(params));		//常规查询条件SQL语句
		if(params.containsKey("selIdList")){
			params.put("selIdList",params.get("selIdList").toString().split(","));
		}
		if (params.get("field") == null || params.get("field") == ""){
			String orderBy = "code asc";
			PageUtils.startPageOrder(orderBy);
		}else{
			PageUtils.startPage();
		}
		return productActiveMapper.queryProductActiveList(params);
	}

	/**
	 * 查询已选择的数据
	 * @param params
	 * @return
	 * @throws Exception
	 * @author DH-Xxj
	 */
	@Override
	public List<ProductActiveComponent> queryProductActiveComponentList(Map<String, Object> params) throws Exception {
		params.put(DataFiltering.TABLE_ALIAS, "t1");	//查询表别名
		params.put(DataFiltering.DATA_WHERE, dictionaryForFieldService.getWhereStr(params));		//常规查询条件SQL语句
		if(params.containsKey("selIdList")){
			params.put("selIdList",params.get("selIdList").toString().split(","));
		}
		if (params.get("field") == null || params.get("field") == ""){
			String orderBy = "code asc";
			PageUtils.startPageOrder(orderBy);
		}else{
			PageUtils.startPage();
		}
		return productActiveMapper.queryProductActiveComponentList(params);
	}

	/**
	 * 新增商品库
	 * @param productActiveItems 必要参数：商品库对应实体类（ProductActive）的json格式字符串
	 * @return
	 * @author DH-Xxj
	 */
	@Override
	public AjaxResult insertProductActive(Map<String, Object> params) {
		if (StringUtils.isEmpty(params)) {
			return AjaxResult.error("数据提交失败，必填参数有误！");
		}
		List<ProductActive> productActiveList = JSON.parseArray(params.get("productActiveItems").toString(), ProductActive.class);
		if (productActiveList == null || productActiveList.size() == 0) {
			return AjaxResult.error("请添加需要保存的商品信息。");
		}

		for (ProductActive productActive : productActiveList) {
			productActive.setCreateUser(ShiroUtils.getUserId());
			productActive.setCreateUserName(ShiroUtils.getUserName());
			productActive.setCreateDept(ShiroUtils.getUserDeptPath());
			productActive.setCreateDeptName(ShiroUtils.getUserDeptName());
			productActive.setCreatePosition(ShiroUtils.getUserPositionNameDa());
			productActive.setCreateTime(new Date());
			productActive.setUpdateUser(ShiroUtils.getUserId());
			productActive.setUpdateTime(new Date());
			if (productActive.getGuid() == null || "".equals(productActive.getGuid())){
				productActive.setGuid(RandomValueUtils.getGUID());
			}
			productActiveMapper.insertProductActive(productActive);
		}
		return AjaxResult.success("操作成功");
	}

	/**
	 * 新增商品子件
	 * @param productActiveComponentItems 必要参数：商品子件对应实体类（ProductActiveComponent）的json格式字符串
	 * @return
	 * @author DH-Xxj
	 */
	@Override
	public AjaxResult insertProductActiveComponent(Map<String, Object> params) {
		if (StringUtils.isEmpty(params)) {
			return AjaxResult.error("数据提交失败，必填参数有误！");
		}
		List<ProductActiveComponent> productActiveComponentList = JSON.parseArray(params.get("productActiveComponentItems").toString(), ProductActiveComponent.class);
		if (productActiveComponentList == null || productActiveComponentList.size() == 0) {
			return AjaxResult.error("请添加需要保存的商品子件信息。");
		}

		for (ProductActiveComponent productActiveComponent : productActiveComponentList) {
			if (productActiveComponent.getPcode() == null || "".equals(productActiveComponent.getPcode())){
				return AjaxResult.error("商品子件中母件编码（pcode）不能为空！");
			}
			productActiveComponent.setCreateUser(ShiroUtils.getUserId());
			productActiveComponent.setCreateTime(new Date());
			productActiveComponent.setUpdateUser(ShiroUtils.getUserId());
			productActiveComponent.setUpdateTime(new Date());
			if (productActiveComponent.getGuid() == null || "".equals(productActiveComponent.getGuid())){
				productActiveComponent.setGuid(RandomValueUtils.getGUID());
			}
			productActiveMapper.insertProductActiveComponent(productActiveComponent);
		}
		return AjaxResult.success("操作成功");
	}

	/**
	 * 新增商品竞品库
	 * @param productActiveCompeteItems 必要参数：商品竞品库对应实体类（ProductActiveCompete）的json格式字符串
	 * @return
	 * @author DH-Xxj
	 */
	@Override
	public AjaxResult insertProductActiveCompete(Map<String, Object> params) {
		if (StringUtils.isEmpty(params)) {
			return AjaxResult.error("数据提交失败，必填参数有误！");
		}
		List<ProductActiveCompete> productActiveCompeteList = JSON.parseArray(params.get("productActiveCompeteItems").toString(), ProductActiveCompete.class);
		if (productActiveCompeteList == null || productActiveCompeteList.size() == 0) {
			return AjaxResult.error("请添加需要保存的商品竞品信息。");
		}

		for (ProductActiveCompete productActiveCompete : productActiveCompeteList) {
			if (productActiveCompete.getPcode() == null || "".equals(productActiveCompete.getPcode())){
				return AjaxResult.error("商品竞品中母件编码（pcode）不能为空！");
			}
			productActiveCompete.setCreateUser(ShiroUtils.getUserId());
			productActiveCompete.setCreateTime(new Date());
			productActiveCompete.setUpdateUser(ShiroUtils.getUserId());
			productActiveCompete.setUpdateTime(new Date());
//			if (productActiveCompete.getGuid() == null || "".equals(productActiveCompete.getGuid())){
//				productActiveCompete.setGuid(RandomValueUtils.getGUID());
//			}
			productActiveMapper.insertProductActiveCompete(productActiveCompete);
		}
		return AjaxResult.success("操作成功");
	}

	/**
	 * 保存商品子件（先删除后新增）
	 * @param pcode 必要参数：商品库中的商品编码（code）
	 * @param productActiveComponentItems 必要参数：商品子件对应实体类（ProductActiveComponent）的json格式字符串
	 * @return
	 * @author DH-Xxj
	 */
	@Override
	public AjaxResult saveProductActiveComponent(Map<String, Object> params) {
		if (StringUtils.isEmpty(params)){
			return AjaxResult.error("数据提交失败，必填参数有误！");
		}
		if (params.get("pcode") == null || params.get("pcode") ==""){
			return AjaxResult.error("请提供必要参数（pcode）【商品库中的商品编码（code）】。");
		}
		productActiveMapper.deleteProductActiveComponentBypcode(params.get("pcode").toString());
		List<ProductActiveComponent> productActiveComponentList = JSON.parseArray(params.get("productActiveComponentItems").toString(), ProductActiveComponent.class);
		if (productActiveComponentList != null && productActiveComponentList.size() > 0) {
			for (ProductActiveComponent productActiveComponent : productActiveComponentList) {
				if (productActiveComponent.getPcode() == null || "".equals(productActiveComponent.getPcode())){
					return AjaxResult.error("商品子件中母件编码（pcode）不能为空！");
				}
				productActiveComponent.setCreateUser(ShiroUtils.getUserId());
				productActiveComponent.setCreateTime(new Date());
				productActiveComponent.setUpdateUser(ShiroUtils.getUserId());
				productActiveComponent.setUpdateTime(new Date());
//				if (productActiveComponent.getGuid() == null || "".equals(productActiveComponent.getGuid())){
//					productActiveComponent.setGuid(RandomValueUtils.getGUID());
//				}
				productActiveMapper.insertProductActiveComponent(productActiveComponent);
			}
		}
		return AjaxResult.success("操作成功");
	}

	/**
	 * 保存商品竞品库（先删除后新增）
	 * @param pcode 必要参数：商品库中的商品编码（code）
	 * @param productActiveCompeteItems 必要参数：商品竞品库对应实体类（ProductActiveCompete）的json格式字符串
	 * @return
	 * @author DH-Xxj
	 */
	@Override
	public AjaxResult saveProductActiveCompete(Map<String, Object> params) {
		if (StringUtils.isEmpty(params)){
			return AjaxResult.error("数据提交失败，必填参数有误！");
		}
		if (params.get("pcode") == null || params.get("pcode") ==""){
			return AjaxResult.error("请提供必要参数（pcode）【商品库中的商品编码（code）】。");
		}
		productActiveMapper.deleteProductActiveCompeteBypcode(params.get("pcode").toString());
		List<ProductActiveCompete> productActiveCompeteList = JSON.parseArray(params.get("productActiveCompeteItems").toString(), ProductActiveCompete.class);
		if (productActiveCompeteList != null && productActiveCompeteList.size() > 0) {
			for (ProductActiveCompete productActiveCompete : productActiveCompeteList) {
				if (productActiveCompete.getPcode() == null || "".equals(productActiveCompete.getPcode())){
					return AjaxResult.error("商品竞品中母件编码（pcode）不能为空！");
				}
				productActiveCompete.setCreateUser(ShiroUtils.getUserId());
				productActiveCompete.setCreateTime(new Date());
				productActiveCompete.setUpdateUser(ShiroUtils.getUserId());
				productActiveCompete.setUpdateTime(new Date());
//				if (productActiveCompete.getGuid() == null || "".equals(productActiveCompete.getGuid())){
//					productActiveCompete.setGuid(RandomValueUtils.getGUID());
//				}
				productActiveMapper.insertProductActiveCompete(productActiveCompete);
			}
		}
		return AjaxResult.success("操作成功");
	}

	/**
	 * 修改商品库
	 * @param productActiveItems 必要参数：商品库对应实体类（ProductActive）的json格式字符串
	 * @return
	 * @author DH-Xxj
	 */
	@Override
	public AjaxResult updateProductActive(Map<String, Object> params) {
		List<ProductActive> productActiveList = JSON.parseArray(params.get("productActiveItems").toString(), ProductActive.class);
		if (productActiveList == null || productActiveList.size() == 0) {
            return AjaxResult.error("数据包格式有误，请检查！");
        }
		
		for (ProductActive productActive : productActiveList) {
			productActive.setUpdateUser(ShiroUtils.getUserId());
			productActive.setUpdateTime(new Date());			
			productActiveMapper.updateProductActive(productActive);
		}
		return AjaxResult.success("操作成功！");
	}

	/**
	 * 修改商品子件
	 * @param productActiveComponentItems 必要参数：商品子件对应实体类（ProductActiveComponent）的json格式字符串
	 * @return
	 * @author DH-Xxj
	 */
	@Override
	public AjaxResult updateProductActiveComponent(Map<String, Object> params) {
		List<ProductActiveComponent> productActiveComponentList = JSON.parseArray(params.get("productActiveComponentItems").toString(), ProductActiveComponent.class);
		if (productActiveComponentList == null || productActiveComponentList.size() == 0) {
            return AjaxResult.error("数据包格式有误，请检查！");
        }
		
		for (ProductActiveComponent productActiveComponent : productActiveComponentList) {
			if (productActiveComponent.getPcode() == null || "".equals(productActiveComponent.getPcode())){
				return AjaxResult.error("商品子件中母件编码（pcode）不能为空！");
			}
			productActiveComponent.setUpdateUser(ShiroUtils.getUserId());
			productActiveComponent.setUpdateTime(new Date());			
			productActiveMapper.updateProductActiveComponent(productActiveComponent);
		}
		return AjaxResult.success("操作成功！");
	}

	/**
	 * 修改商品竞品库
	 * @param productActiveCompeteItems 必要参数：商品竞品库对应实体类（ProductActiveCompete）的json格式字符串
	 * @return
	 * @author DH-Xxj
	 */
	@Override
	public AjaxResult updateProductActiveCompete(Map<String, Object> params) {
		List<ProductActiveCompete> productActiveCompeteList = JSON.parseArray(params.get("productActiveCompeteItems").toString(), ProductActiveCompete.class);
		if (productActiveCompeteList == null || productActiveCompeteList.size() == 0) {
            return AjaxResult.error("数据包格式有误，请检查！");
        }
		
		for (ProductActiveCompete productActiveCompete : productActiveCompeteList) {
			if (productActiveCompete.getPcode() == null || "".equals(productActiveCompete.getPcode())){
				return AjaxResult.error("商品竞品中母件编码（pcode）不能为空！");
			}
			productActiveCompete.setUpdateUser(ShiroUtils.getUserId());
			productActiveCompete.setUpdateTime(new Date());			
			productActiveMapper.updateProductActiveCompete(productActiveCompete);
		}
		return AjaxResult.success("操作成功！");
	}

	/**
	 * 通过Guid删除商品库
	 * @param productActiveItems 必要参数：商品库对应实体类（ProductActive）的json格式字符串
	 * @return
	 * @author DH-Xxj
	 */
	@Override
	public AjaxResult deleteProductActiveByGuid(Map<String, Object> params) {
		List<ProductActive> productActiveList = JSON.parseArray(params.get("productActiveItems").toString(), ProductActive.class);
		if (productActiveList == null || productActiveList.size() == 0) {
            return AjaxResult.error("数据包格式有误，请检查！");
        }

//		for (ProductActive productActive : productActiveList) {
//			productActiveMapper.deleteProductActiveByGuid(productActive.getGuid() == null ? "noguid" : productActive.getGuid());
//		}
		return AjaxResult.success("操作成功");
	}

	/**
	 * 通过Guid删除商品库（完整删除，包含子件和竞品）
	 * @param productActiveItems 必要参数：商品库对应实体类（ProductActive）的json格式字符串
	 * @return
	 * @author DH-Xxj
	 */
	@Override
	public AjaxResult deleteProductActiveCompleteByGuid(Map<String, Object> params) {
		List<ProductActive> productActiveList = JSON.parseArray(params.get("productActiveItems").toString(), ProductActive.class);
		String pcode = ""; //商品母件编码
		if (productActiveList == null || productActiveList.size() == 0) {
            return AjaxResult.error("数据包格式有误，请检查！");
        }

		for (ProductActive productActive : productActiveList) {
			if (productActive.getCode() != null){
				pcode = productActive.getCode().toString();
				productActiveMapper.deleteProductActiveComponentBypcode(pcode);
				productActiveMapper.deleteProductActiveCompeteBypcode(pcode);
			}
			productActiveMapper.deleteProductActiveByGuid(productActive.getGuid() == null ? "noguid" : productActive.getGuid());
		}
		return AjaxResult.success("操作成功");
	}

	/**
	 * 通过Guid删除商品子件
	 * @param productActiveComponentItems 必要参数：商品子件对应实体类（ProductActiveComponent）的json格式字符串
	 * @return
	 * @author DH-Xxj
	 */
	@Override
	public AjaxResult deleteProductActiveComponentByGuid(Map<String, Object> params) {
		List<ProductActiveComponent> productActiveComponentList = JSON.parseArray(params.get("productActiveComponentItems").toString(), ProductActiveComponent.class);
		if (productActiveComponentList == null || productActiveComponentList.size() == 0) {
            return AjaxResult.error("数据包格式有误，请检查！");
        }

		for (ProductActiveComponent productActiveComponent : productActiveComponentList) {
			productActiveMapper.deleteProductActiveComponentByGuid(productActiveComponent.getGuid() == null ? "noguid" : productActiveComponent.getGuid());
		}
		return AjaxResult.success("操作成功");
	}

	/**
	 * 通过Guid删除商品竞品库
	 * @param productActiveCompeteItems 必要参数：商品竞品库对应实体类（ProductActiveCompete）的json格式字符串
	 * @return
	 * @author DH-Xxj
	 */
	@Override
	public AjaxResult deleteProductActiveCompeteByGuid(Map<String, Object> params) {
		List<ProductActiveCompete> productActiveCompeteList = JSON.parseArray(params.get("productActiveCompeteItems").toString(), ProductActiveCompete.class);
		if (productActiveCompeteList == null || productActiveCompeteList.size() == 0) {
            return AjaxResult.error("数据包格式有误，请检查！");
        }

//		for (ProductActiveCompete productActiveCompete : productActiveCompeteList) {
//			productActiveMapper.deleteProductActiveCompeteByGuid(productActiveCompete.getGuid() == null ? "noguid" : productActiveCompete.getGuid());
//		}
		return AjaxResult.success("操作成功");
	}
	
	/**
	 * 从商品库调入
	 * @param params
	 * @return List - ProductActive
	 * @throws Exception
	 * @author DH-Xxj
	 */
//	@Override
	public List<ProductActive> queryCallProductXG(Map<String, Object> params) throws Exception{
        params.put(DataFiltering.TABLE_ALIAS, "t1");	//查询表别名
        params.put(DataFiltering.DATA_WHERE, dictionaryForFieldService.getWhereStr(params));	//常规查询条件SQL语句
        params.put(DataFiltering.DATA_SCODE, dictionaryForFieldService.getDataScode(params));	//数据权限查询条件SQL语句

		if (params.get("field") == null || params.get("field") == ""){
			String orderBy = "name asc";
			PageUtils.startPageOrder(orderBy);
		}else{
			PageUtils.startPage();
		}
		
		return productActiveMapper.callProductXG(params);
	}
	
}
